package com.itboye.sunsun.adapter;

import java.util.ArrayList;

import com.itboye.sunsunhome.R;
import com.itboye.sunsun.beans.NewsHotReaBean;
import com.itboye.sunsun.utils.XImageLoader;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class NewsHotReadAdapter extends BaseAdapter {

	ArrayList<NewsHotReaBean.AllData.AllList> arrayList;
	Context context;
	private int op;
	public NewsHotReadAdapter(
			ArrayList<NewsHotReaBean.AllData.AllList> arrayList, Context context) {
		this.arrayList = arrayList;
		this.context = context;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return arrayList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return arrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		return 6;
	}

	@Override
	public int getItemViewType(int position) {
		op = position;
		if (op == 0)
			op = 0;
		else
			op = 1;
		return op;
	}

	Holder holder = null;

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {
			holder = new Holder();
			// if (op == 0)
			// convertView = LayoutInflater.from(context).inflate(
			// R.layout.news_list_header, null);
			// else if (op == 1)
			convertView = LayoutInflater.from(context).inflate(
					R.layout.newshot_item, null);

			holder.txt_content = (TextView) convertView
					.findViewById(R.id.txt_content);
			holder.txt_title = (TextView) convertView
					.findViewById(R.id.txt_title);
			holder.img = (ImageView) convertView.findViewById(R.id.img);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		XImageLoader.load(arrayList.get(position).getMainImg(), holder.img);
		holder.txt_title.setText(arrayList.get(position).getPostTitle());
		holder.txt_content.setText(arrayList.get(position).getPostExcerpt());
		return convertView;
	}

	public class Holder {
		ImageView img;
		TextView txt_title, txt_content;
	}
}
